package com.example.demo.controller;

import com.example.demo.model.Category;
import com.example.demo.model.Drink;
import com.example.demo.service.ICategoryService;
import com.example.demo.service.IDrinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class RouterController {
    @Autowired
    public IDrinkService iDrinkService;

    @Autowired
    public ICategoryService iCategoryService;
//    登录页面路由
    @GetMapping("/")
    public String Login(){
        return "manage/login";
    }
//    后台首页路由
    @GetMapping("/manage/index")
    public String index(){
        return "manage/index";
    }
    // 后台欢迎路由
    @GetMapping("/manage/welcome")
    public String welcome(){
        return "manage/welcome";
    }

    //饮品管理菜单首页路由
    //get /menu/drink
    @GetMapping("/menu/drink")
    public String getDrinkIndex(){
        return "drink/index";
    }

    //添加页面路由添加饮品
//    /get /drink/addform
    @GetMapping("/drink/addform")
    public String getAddForm(){
        return "drink/add";
    }

//    编辑饮品
//     /put /drink/updateform?id=xxx
    @GetMapping("/drink/updateform")
    public ModelAndView getUpdateFrom(@RequestParam Integer id){
        ModelAndView mv = new ModelAndView("drink/edit");
        // 后期从数据库查询
        Drink build=iDrinkService.getDrinkById(id);
        mv.addObject("drink",build);
        return mv;
    }
    //分类管理菜单首页路由
    //get /menu/drink
    @GetMapping("/menu/category")
    public String getCategoryIndex(){
        return "category/index";
    }

//    分类管理新增分类
    @GetMapping("/category/addform")
    public String addNewFrom(){
        return "category/add";
    }

//    分类管理编辑分类
    @GetMapping("/category/updateform")
    public ModelAndView updateForm(@RequestParam Integer id){
        ModelAndView mv=new ModelAndView("category/edit");
        Category category=iCategoryService.getCategoryById(id);
        mv.addObject("category",category);
        return mv;
    }
}
